<!-- 选项设置->销售 -->
<template>
  <a-row style="height:100%;position:relative;">
    <a-col span="24" style="height: calc(100% - 50px);overflow-y:auto;min-height:200px;">
      <!---基础业务--->
      <a-col span="24">
        <card-wrapper :title="'基础业务'">
          <template v-slot:slot-1>
            <a-row v-for="(item, index) in data" :key="index">
              <a-col v-if="item.parentName=='基础业务'" :span="24" @mouseenter="hover(item)" class="back">
                <!-- 销货单自动生成出库单 -->
                <a-col v-if="item.code == 'IsDeliveryOrderAutoStockOrder'" :span="24">
                  <a-checkbox class="padding-5" v-show="item.isVisible==1" :disabled="item.isEnable==0" :checked="item.value!=0" @change="value => handleChange(value,item.code)">{{ item.name }}</a-checkbox>
                  <div v-show="item.value!=0">
                    <span class="line-h35 padding-left-28">出库单日期取销货单:</span>
                    <a-radio-group class="text-after-radio padding-left-8" :disabled="item.isEnable == 0" :value="Number(item.value)" @change="value => handleRadioChange(value,item.code)">
                      <a-radio :value="1">
                        单据日期
                      </a-radio>
                      <a-radio :value="2">
                        审核日期
                      </a-radio>
                    </a-radio-group>
                  </div>
                </a-col>
                <a-checkbox v-if="item.code != 'IsDeliveryOrderAutoStockOrder' && item.code!='ValidInventory'" class="padding-5" :disabled="item.isVisible==0" :checked="item.isEnable==0" @change="value => handleChange(value,item.code)">{{ item.name }}</a-checkbox>
              </a-col>
            </a-row>
            <a-row v-for="(item, index) in data" :key="index">
              <!-- 录入物料时检测物料重复录入（按物料＋自由项） -->
              <a-col v-if="item.code=='ValidInventory'" :span="24" @mouseenter="hover(item)" class="back">
                <a-checkbox class="padding-5" v-show="item.isVisible==1" :disabled="item.isEnable==0" :checked="item.value!=0" @change="value => handleChange(value,item.code)">{{ item.name }}</a-checkbox>
              </a-col>
            </a-row>
            <a-row v-for="(item, index) in data" :key="index" class="padding-left-20">
                <!-- 销货单 -->
                <a-col v-if="item.code == 'IsSDAvilableControl'" :span="24" @mouseenter="hover(item)" class="back">
                  <a-checkbox class="padding-5" v-show="item.isVisible==1" :disabled="item.isEnable==0" :checked="item.value!=0" @change="value => handleChange(value,item.code)">{{ item.name }}</a-checkbox>
                </a-col>
                <!-- 销售订单 -->
                <a-col v-if="item.code == 'IsSOAvilableControl'" :span="24" @mouseenter="hover(item)" class="back">
                  <a-checkbox class="padding-5" v-show="item.isVisible==1" :disabled="item.isEnable==0" :checked="item.value!=0" @change="value => handleChange(value,item.code)">{{ item.name }}</a-checkbox>
                </a-col>
            </a-row>

          </template>
        </card-wrapper>
      </a-col>

      <!---信用控制--->
      <a-col span="24">
        <card-wrapper :title="'信用控制'">
          <template v-slot:slot-1>

            <!-- 控制时机 -->
            <a-row v-for="(item, index) in data" :key="index">
              <a-col v-if="item.code=='IsControllerOpportunity'" :span="24" @mouseenter="hover(item)" class="back">
                <a-col class="padding-5" :span="24">
                  <span class="line-h35">{{item.name}}:</span>
                  <a-radio-group class="text-after-radio padding-left-8" v-show="item.isVisible==1" :disabled="item.isEnable==0" :value="Number(item.value)" @change="value => handleRadioChange(value,item.code)">
                    <a-radio :value="1">
                      保存
                    </a-radio>
                    <a-radio :value="2">
                      审核
                    </a-radio>
                  </a-radio-group>
                </a-col>
              </a-col>
            </a-row>

            <!-- 客户信用控制IsCustomerCreditControl(控制范围HighestPPriceControlMode，控制方式CustomerCreditContolRange，密码：CustomerPassword，确认密码：CustomerConfirmPassword) -->
            <a-row v-for="(item, index) in data" :key="index">
              <a-col v-if="item.code=='IsCustomerCreditControl'" :span="24" @mouseenter="hover(item)" class="back">
                <a-checkbox class="padding-5" v-show="item.isVisible==1" :disabled="item.isEnable==0" :checked="item.value!=0" @change="value => handleChange(value,item.code)">{{ item.name }}</a-checkbox>
              </a-col>
            </a-row>
            <a-row v-for="(item, index) in data" :key="index">
              <a-col v-if="item.code == 'CustomerCreditContolRange' || item.code =='HighestPPriceControlMode'" :span="24" @mouseenter="hover(item)" class="back">
                <div v-show="item.isEnable == 1" class="clearfix">
                  <div class="line-h35 padding-left-28" style="float:left">{{item.name}}</div>
                  <div v-show="item.code == 'HighestPPriceControlMode'" style="float:left">
                    <a-radio-group class="text-after-radio padding-left-8" v-show="item.isVisible==1" :disabled="item.isEnable==0" :value="Number(item.value)" @change="value => handleRadioChange(value,item.code)">
                      <a-radio :value="1">
                        额度
                      </a-radio>
                      <a-radio :value="2">
                        期限
                      </a-radio>
                      <a-radio :value="3">
                        额度和期限
                      </a-radio>
                    </a-radio-group>
                  </div>
                  <div v-show="item.code == 'CustomerCreditContolRange'" style="float:left">
                    <a-radio-group class="text-after-radio padding-left-8" v-show="item.isVisible==1" :disabled="item.isEnable==0" :value="Number(item.value)" @change="value => handleRadioChange(value,item.code)">
                      <a-radio :value="1">
                        提示
                      </a-radio>
                      <a-radio :value="2">
                        密码
                      </a-radio>
                      <a-radio :value="3">
                        禁止
                      </a-radio>
                    </a-radio-group>
                    <div v-show="item.value==2" class="pwd-box">
                      <a-row>
                        <a-col :span="8">密　　码</a-col>
                        <a-col :span="15" class="margin-left-5">
                          <div v-for="(temp, index) in tempData" :key="index">
                            <a-row v-if="temp.code=='CustomerPassword'">
                              <a-input type="password" size="small" v-model="temp.value" @change="handlePassword(temp.code)"></a-input>
                            </a-row>
                          </div>
                        </a-col>
                      </a-row>
                      <a-row>
                        <a-col :span="8">确认密码</a-col>
                        <a-col :span="15" class="margin-left-5">
                          <div v-for="(temp, index) in tempData" :key="index">
                            <a-row v-if="temp.code=='CustomerConfirmPassword'">
                              <a-input type="password" size="small" v-model="temp.value" @change="handlePassword(temp.code)" @blur="handleConfirmPassword('客户信用控制','CustomerPassword','CustomerConfirmPassword')"></a-input>
                            </a-row>
                          </div>
                        </a-col>
                      </a-row>
                    </div>
                  </div>
                </div>
              </a-col>
            </a-row>

            <!-- 业务员信用控制IsSalerCreditControl(控制范围IsManuProcessControlRange，控制方式IsControlMode) -->
            <a-row v-for="(item, index) in data" :key="index">
              <a-col v-if="item.code=='IsSalerCreditControl'" :span="24" @mouseenter="hover(item)" class="back">
                <a-checkbox class="padding-5" v-show="item.isVisible==1" :disabled="item.isEnable==0" :checked="item.value!=0" @change="value => handleChange(value,item.code)">{{ item.name }}</a-checkbox>
              </a-col>
            </a-row>
            <a-row v-for="(item, index) in data" :key="index">
              <a-col v-if="item.code == 'IsManuProcessControlRange' || item.code =='IsControlMode'" :span="24" @mouseenter="hover(item)" class="back">
                <div v-show="item.isEnable == 1" class="clearfix">
                  <div class="line-h35 padding-left-28" style="float:left">{{item.name}}</div>
                  <div v-show="item.code == 'IsManuProcessControlRange'" style="float:left">
                    <a-radio-group class="text-after-radio padding-left-8" v-show="item.isVisible==1" :disabled="item.isEnable==0" :value="Number(item.value)" @change="value => handleRadioChange(value,item.code)">
                      <a-radio :value="1">
                        额度
                      </a-radio>
                      <a-radio :value="2">
                        期限
                      </a-radio>
                      <a-radio :value="3">
                        额度和期限
                      </a-radio>
                    </a-radio-group>
                  </div>
                  <div v-show="item.code == 'IsControlMode'" style="float:left">
                    <a-radio-group class="text-after-radio padding-left-8" v-show="item.isVisible==1" :disabled="item.isEnable==0" :value="Number(item.value)" @change="value => handleRadioChange(value,item.code)">
                      <a-radio :value="1">
                        提示
                      </a-radio>
                      <a-radio :value="2">
                        密码
                      </a-radio>
                      <a-radio :value="3">
                        禁止
                      </a-radio>
                    </a-radio-group>
                    <div v-show="item.value==2" class="pwd-box">
                      <a-row>
                        <a-col :span="8">密　　码</a-col>
                        <a-col :span="15" class="margin-left-5">
                          <div v-for="(temp, index) in tempData" :key="index">
                            <a-row v-if="temp.code=='SalesmanPassword'">
                              <a-input type="password" size="small" v-model="temp.value" @change="handlePassword(temp.code)"></a-input>
                            </a-row>
                          </div>
                        </a-col>
                      </a-row>
                      <a-row>
                        <a-col :span="8">确认密码</a-col>
                        <a-col :span="15" class="margin-left-5">
                          <div v-for="(temp, index) in tempData" :key="index">
                            <a-row v-if="temp.code=='SalesmanConfirmPassword'">
                              <a-input type="password" size="small" v-model="temp.value" @change="handlePassword(temp.code)" @blur="handleConfirmPassword('业务员信用控制','SalesmanPassword','SalesmanConfirmPassword')"></a-input>
                            </a-row>
                          </div>
                        </a-col>
                      </a-row>
                    </div>
                  </div>
                </div>
              </a-col>
            </a-row>

            <!-- 信用额占用【占用量=已订未出货+已出货未立账+销售应收款+其他应收款-预收款-费用单（冲减应收）】 -->
            <a-row v-for="(item, index) in data" :key="index">
              <a-col v-if="item.code=='CreditOccupation'" :span="24" @mouseenter="hover(item)" class="back">{{item.name}}</a-col>
              <a-col v-if="item.parentName == '信用额占用'" :span="24" @mouseenter="hover(item)" class="back">
                <a-row class="padding-left-20">
                  <a-checkbox class="padding-5" v-show="item.isVisible==1" :disabled="item.isEnable==0" :checked="item.value!=0" @change="value => handleChange(value,item.code)">{{ item.name }}</a-checkbox>
                </a-row>
              </a-col>
            </a-row>

          </template>
        </card-wrapper>
      </a-col>

      <!--最低售价控制-->
      <a-col span="24">
        <card-wrapper :title="'最低售价控制'">
          <template v-slot:slot-1>
            <a-row v-for="(item, index) in data" :key="index">
              <a-col v-if="item.parentName=='最低售价控制'" :span="24" @mouseenter="hover(item)" class="back">
                <!-- 最低售价控制->控制时机   最低售价控制->控制方式  -->
                <a-col v-if="item.code == 'SalePriceControlTiming' || item.code =='SalePriceControlMode'" :span="24">
                  <div v-show="item.isEnable == 1" class="clearfix">
                    <div class="line-h35 padding-left-28" style="float:left">{{item.name}}</div>
                    <div v-show="item.code == 'SalePriceControlTiming'" style="float:left">
                      <a-radio-group class="text-after-radio padding-left-8" v-show="item.isVisible==1" :disabled="item.isEnable==0" :value="Number(item.value)" @change="value => handleRadioChange(value,item.code)">
                        <a-radio :value="1">
                          保存
                        </a-radio>
                        <a-radio :value="2">
                          审核
                        </a-radio>
                      </a-radio-group>
                    </div>
                    <div v-show="item.code == 'SalePriceControlMode'" style="float:left">
                      <a-radio-group class="text-after-radio padding-left-8" v-show="item.isVisible==1" :disabled="item.isEnable==0" :value="Number(item.value)" @change="value => handleRadioChange(value,item.code)">
                        <a-radio :value="1">
                          提示
                        </a-radio>
                        <a-radio :value="2">
                          密码
                        </a-radio>
                        <a-radio :value="3">
                          禁止
                        </a-radio>
                      </a-radio-group>
                      <div v-show="item.value==2" class="pwd-box">
                        <a-row>
                          <a-col :span="8">密　　码</a-col>
                          <a-col :span="15" class="margin-left-5">
                            <div v-for="(temp, index) in tempData" :key="index">
                              <a-row v-if="temp.code=='ControlModePassword'">
                                <a-input type="password" size="small" v-model="temp.value" @change="handlePassword(temp.code)"></a-input>
                              </a-row>
                            </div>
                          </a-col>
                        </a-row>
                        <a-row>
                          <a-col :span="8">确认密码</a-col>
                          <a-col :span="15" class="margin-left-5">
                            <div v-for="(temp, index) in tempData" :key="index">
                              <a-row v-if="temp.code=='ControlModeConfirmPassword'">
                                <a-input type="password" size="small" v-model="temp.value" @change="handlePassword(temp.code)" @blur="handleConfirmPassword('最低售价控制','ControlModePassword','ControlModeConfirmPassword')"></a-input>
                              </a-row>
                            </div>
                          </a-col>
                        </a-row>
                      </div>
                    </div>

                  </div>
                </a-col>
                <a-checkbox v-else class="padding-5" v-show="item.isVisible==1" :disabled="item.isEnable==0" :checked="item.value!=0" @change="value => handleChange(value,item.code)">{{ item.name }}</a-checkbox>

              </a-col>
            </a-row>
          </template>
        </card-wrapper>
      </a-col>

    </a-col>
    <div class="btn-save">
      <div class="box">
        <a-button type="primary" @click="submit">保存</a-button>
      </div>
    </div>
  </a-row>
</template>
<script>
import { cardWrapper } from "@/components/CardWrapper"; // 分类外框
import { list, save } from "@/api/erp/accountRuleSet"; //选项设置接口

export default {
  props: {},
  data() {
    return {
      data: {}, // 数据
      type: "", //获取数据类型

      tempData: [], //临时数组
      pushDataGo: true, //阻止提交
    };
  },
  components: {
    cardWrapper,
  },
  created() {},
  methods: {
    hover(item) {
      this.$emit("description", item);
    },
    handleChange(event, code) {
      //多选框点击事件
      console.log(event);

      for (let i = 0; i < this.data.length; i++) {
        if (this.data[i].code == code) {
          if (event.target.checked) {
            // this.$set(this.data[i], "isEnable", "1"); //启用
            this.$set(this.data[i], "value", "1");
          } else {
            // this.$set(this.data[i], "isEnable", "0"); //禁用
            this.$set(this.data[i], "value", "0");
          }
        }
      }
    },
    handleInputChange(event, code) {
      //输入框事件
      console.log(event);
      for (let i = 0; i < this.data.length; i++) {
        if (this.data[i].code == code) {
          this.data[i].value = event.data;
        }
      }
      console.log(this.data);
    },
    handleRadioChange(event, code) {
      //单选框事件
      console.log(event);
      for (let i = 0; i < this.data.length; i++) {
        if (this.data[i].code == code) {
          this.data[i].value = event.target.value;
        }
      }
      console.log(this.data);
    },
    handlePassword(code) {
      for (let i = 0; i < this.tempData.length; i++) {
        if (this.tempData[i].code == code) {
          this.$set(this.data[i], "value", this.tempData[i].value);
        }
      }
    },
    handleConfirmPassword(source, cdoe, again_code) {
      //鼠标移出 判断两次输入的密码是否一致
      let tempa = "",
        tempb = "";
      for (let i = 0; i < this.tempData.length; i++) {
        if (this.tempData[i].code == cdoe) {
          tempa = this.tempData[i].value;
        }
        if (this.tempData[i].code == again_code) {
          tempb = this.tempData[i].value;
        }
      }

      if (tempa != tempb) {
        this.$message.error(`${source}两次密码输入不一致`, 3);
        this.pushDataGo = false;
      } else {
        this.pushDataGo = true;
      }
    },
    submit() {
      //提交数据
      if (this.pushDataGo) {
        save(this.data)
          .then((response) => {
            if (response.code == 200) {
              this.$message.success("修改成功");
              this.$emit("refresh", "2");
            }
          })
          .catch((error) => {});
      } else {
        // @blur="handleOncePassword('客户信用控制','CustomerPassword','CustomerConfirmPassword')"
        // handleConfirmPassword('业务员信用控制','SalesmanPassword','SalesmanConfirmPassword')"
        // @blur="handleConfirmPassword('最低售价控制','ControlModePassword','ControlModeConfirmPassword')"

        // for (const key in this.data) {
        //   if(this.data[key].code == 'CustomerPassword'){

        //   }
        // }
        this.$message.error(`密码输入有误请检查`);
      }
    },
    getData(type) {
      this.type = type;
      list({ moduleCode: type })
        .then((response) => {
          if (response.code == 200) {
            this.data = response.data;
            this.tempData = response.data; //临时
          }
        })
        .catch((error) => {});
    },
  },
};
</script>
<style lang="less" scoped>
.back:hover {
  background: #eee;
}

.padding-5 {
  padding: 5px;
  display: block;
}
.padding-4 {
  padding: 4px 0;
}

.btn-save {
  width: 100%;
  height: 50px;
  line-height: 50px;
  box-shadow: 0 0 10px #ddd;
  text-align: center;
  position: absolute;
  bottom: 0;
  .btn {
    margin-right: 10px;
  }
}

.text-after-input {
  padding: 4px 0;
}

.text-after-radio {
  line-height: 35px;
  padding-left: 5px;
}
.color-777 {
  color: #777;
}
.pwd-box {
  text-align: justify;
  text-align-last: justify;
  line-height: 35px;
}
</style>